package
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;
	import flash.xml.XMLNodeType;
	
	public class XMLtest extends Sprite
	{
		private var Loader:URLLoader;
		private var xmlData:XML;
		private var _URL:String;
		private var xmlDataURL:URLRequest;
		private var xmlLoader:URLLoader;
		
		private var iStage_num_Rec:Number ;      //场景号
		private var iLevel_num_Rec:Number ;		//关卡号
		
		public function XMLtest()
		{
			Loader = new URLLoader();
			xmlData = new XML();
			_URL = "XML1.2Beta.xml";
			xmlDataURL = new URLRequest(_URL);
			xmlLoader = new URLLoader(xmlDataURL);
			
			iStage_num_Rec = 1;      //场景号
			iLevel_num_Rec = 5;		//关卡号
			
			trace ("Begin:");
			loadXml();
		}
		
		public function loadXml() :void
		{
			xmlLoader.addEventListener(Event.COMPLETE, onLoaded);
		}
		
		public function onLoaded(evtObj:Event):void 
		{
			xmlData = XML(xmlLoader.data);
			OutputXml();
		}
		
		public function OutputXml():void 
		{
			var iStage_num:int = iStage_num_Rec;
			var iLevel_num:int = iLevel_num_Rec;
			var iEnemy_Length:int = xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).enemy.length();
			var iProperty_Length:int = xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).property.length();
			
			var iEnemy_appear_time:int;
			var iEnemy_enemy_type:int;
			var iEnemy_position_x:int;
			var iEnemy_position_y:int;
			
			var iProperty_appear_time:int;
			var iProperty_type:int;
			var iProperty_type_String:String;
			var iProperty_type_String_length:int;

			var arrProperty_num:int;
	
			for(var i:Number = 0;i<iEnemy_Length;i++)
			{
				iEnemy_appear_time = xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).enemy[i].@appear_time;
				iEnemy_enemy_type =  xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).enemy[i].@enemy_type;
				iEnemy_position_x =  xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).enemy[i].@position_x;
				iEnemy_position_y =  xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).enemy[i].@position_y;
				//——————————————————————————————这里写构造函数（敌人）
		
			}
		
			for(var j:Number = 0;j<iProperty_Length;j++)
			{
				var arrProperty:Array = new Array();
				iProperty_appear_time = xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).property[j].@appear_time;
				iProperty_type = xmlData.my_stage.(@id == iStage_num).my_level.(@id == iLevel_num).property[j].@property_type;
				
				iProperty_type_String = iProperty_type.toString();
				
				iProperty_type_String_length = iProperty_type_String.length;
				
				trace(j+":"+iProperty_type_String_length);
				for(var p:Number = 0;p<iProperty_type_String_length;p++)
				{
					arrProperty_num = iProperty_type_String.charCodeAt(p)-48;
					arrProperty.push(arrProperty_num);
				}
				
				for (var h:Number = 0; h< arrProperty.length; h++)
				{
					trace(arrProperty[h])
					//——————————————————————————————这里写构造函数（道具）
				}
				
			}
		}
	}
}

